package com.mokio.controller;

import com.mokio.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @program: xiaomishop
 * @ClassName AdminController
 * @description:
 * @author: mokio
 * @create: 2024−12-10 16:33
 * @Version 1.0
 **/
@Controller
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;
    @RequestMapping("/login.action")
    public String login(@RequestParam("name")String username, @RequestParam("pwd") String password, Model model) {

        String login = adminService.login(username, password);
        if ("yes".equals(login)) {
            //用户登录信息合法，存储用户名
            model.addAttribute("adminName", username);
            return "main";
        }else {
            //用户信息不合法，返回错误信息
            model.addAttribute("errmsg", "用户名或密码错误！");
            return "login";
        }
    }

}
